file chooser button: Fix some refcounting confusion
authorMatthias Clasen <mclasen@redhat.com>
Thu, 6 Aug 2015 12:51:25 +0000 (14:51 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 6 Aug 2015 12:51:25 +0000 (14:51 +0200)
GtkFileSystem has a complicated way to handle cancellables.
You keep the cancellable pointer that is returned by
_gtk_file_system_get_info and similar methods so that you can
cancel the operation, but you do not own a reference to it.
The only place where it is ok to unref a cancellable is in
your callback, which gets handed a cancellable that you need
to unref at the end. You are expected to compare it to the
pointer you stashed away to find out if the operation has
already been superseded by a newer call, in which case you
disregard the results.

GtkFileChooserButton was following these rules for most of
the cancellables it keeps around, but it was sometimes unreffing
the cancellables that are stored in the model, which could lead
to refcount confusion and crashes. This commit makes it follow
the rules for that case too, which fixes the crash in the bug
below, and does not show up any leaks in valgrind under light
testing.

https://bugzilla.gnome.org/show_bug.cgi?id=737804

gtk/gtkfilechooserbutton.c

index a7fb92309eb4741ecfd6f3a693281edf93237086..7a91af1625bdd7e21b997a387153b79f59e620d8 100644 (file)
@@ -1580,8 +1580,7 @@ out:
   gtk_tree_row_reference_free (data->row_ref);
   g_free (data);
 
-  if (model_cancellable)
-    g_object_unref (model_cancellable);
+  g_object_unref (cancellable);
 }
 
 static void
@@ -1684,10 +1683,7 @@ model_free_row_data (GtkFileChooserButton *button,
                      -1);
 
   if (cancellable)
-    {
-      g_cancellable_cancel (cancellable);
-      g_object_unref (cancellable);
-    }
+    g_cancellable_cancel (cancellable);
 
   switch (type)
     {
@@ -1767,8 +1763,7 @@ out:
   gtk_tree_row_reference_free (data->row_ref);
   g_free (data);
 
-  if (model_cancellable)
-    g_object_unref (model_cancellable);
+  g_object_unref (cancellable);
 }
 
 static void
@@ -2792,6 +2787,7 @@ combo_box_notify_popup_shown_cb (GObject    *object,
 
   /* If the combo box popup got dismissed, go back to showing the ROW_TYPE_EMPTY_SELECTION if needed */
   if (!popup_shown)
+
     {
       GFile *selected = get_selected_file (button);